package com.hmdp.test.asr;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * ASR控制器
 */
@RestController
@RequestMapping("/asr")
public class ASRController {
    private final ASRServiceFactory asrServiceFactory;
    
    public ASRController(ASRServiceFactory asrServiceFactory) {
        this.asrServiceFactory = asrServiceFactory;
    }
    
    /**
     * 文本转语音
     */
    @PostMapping("/tts")
    public ASRResponse textToSpeech(@RequestParam String text,
                                  @RequestParam String vendor) {
        ASRRequest request = new ASRRequest(text, vendor);
        ASRService service = asrServiceFactory.getASRService(vendor);
        return service.textToSpeech(request);
    }
    
    /**
     * 语音转文本
     */
    @PostMapping("/stt")
    public ASRResponse speechToText(@RequestParam String audioData, 
                                  @RequestParam String vendor) {
        ASRRequest request = new ASRRequest(audioData, vendor);
        ASRService service = asrServiceFactory.getASRService(vendor);
        return service.speechToText(request);
    }
}